
#include "mkdirDispose.h"


void mkdirDispose(char * str,int sockfd,char * cpath){
    char command[] = "mkdir";
    cpath[strlen(cpath)-1] = '\0';

    Train train;
    train.length = strlen(command);            //向后台发送puts信号
    memcpy(train.data,command,train.length);
    send(sockfd,&train,sizeof(train.length)+train.length,MSG_NOSIGNAL);
    printf("mkdirsend:%s\n",str);
    train.length = strlen(cpath);         //发送服务器该传输的位置(父文件路径)
    memcpy(train.data,cpath,train.length);
    send(sockfd,&train,sizeof(train.length)+train.length,MSG_NOSIGNAL);
   
    int epollfd = epoll_create(1);
    struct epoll_event event;
    event.events = EPOLLIN;
    event.data.fd = sockfd;
    epoll_ctl(epollfd,EPOLL_CTL_ADD,sockfd,&event) ;
    struct epoll_event readyset[5];
    epoll_wait(epollfd,readyset,5,-1);

    char has;
    recv(readyset[0].data.fd,&has,1,MSG_WAITALL);
    if(has == '0'){
        printf("file path failed!\n");
        return ;
    }

  int i = strlen(str)-1;
    while(i>=0){
        if(str[i] == '/'){
            break;
        }
        --i;
    }
    char filename[1024] = {0};
    for(int j = i + 1 , k = 0; j < strlen(str) ; ++j,++k){
        filename[k] = str[j];
    }   
 
    train.length = strlen(filename);
    memcpy(train.data,filename,train.length);
    send(sockfd,&train,sizeof(train.length)+train.length,MSG_NOSIGNAL);
    
    train.length = strlen(str);
    memcpy(train.data,str,train.length);
    send(sockfd,&train,sizeof(train.length)+train.length,MSG_NOSIGNAL);


    printf("success\n");


}

